﻿@using XRM.Security.WebUI.MvcHelpers
@model XRM.Security.WebUI.Models.UserSkzi.UserSkziModel
@{
    ViewBag.Title = "Внесение информации об СКЗИ";
    Layout = "~/Views/Shared/_LayoutDialog.cshtml";
}

<style type="text/css">
</style>

<div class="modal-body">
    @using (Html.BeginForm("AddUserSkziDialog", "UserRegister", FormMethod.Post, new { id = "dlgAddUserSkziDialogForm", @class = "form-horizontal form-horizontal-2" }))
    {      
        @Html.AntiForgeryToken()
        @Html.HiddenFor(m => m.Id)
        @Html.HiddenFor(m => m.UserRegisterId)
        @Html.HiddenFor(m => m.AllowUserChange)

        @Html.DialogFormButton(new DialogButtonOptions()
            {
                    Text = "Выбрать пользователя",
                    ContentUrl = Url.Action("ADUsersDialog", "UserRegister"),
                    Width = "800",
                    Id = "dlgADUsersDialog",
                    ButtonCss = "btn btn-large btn-primary hidden",
                    OnSuccess = "GetSelectedUser",
                    ButtonId = "btnSelectUser",
                    OnOpen = "InitSearchUsersDialog"
            })

        const string inputCss = "form-control";
        const string divCss = "col-sm-6";
        
        <div class="form-group">
            @Html.Label("Пользователь", new { @class = "control-label required" })
            
            @if ((Model.UserRegisterId <= 0) || (Model.AllowUserChange))
            {
                <div class="@divCss">
                    <div class="input-group">
                        @Html.TextBox("tbUserFullName", Model.UserRegisterFullName, new { @class = @inputCss })
                        <span class="input-group-btn">
                            <button id="btnSearch" class="btn btn-default" type="button"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </div>
            }
            else
            {
                <div class="@divCss control-text">
                    @Model.UserRegisterFullName
                </div>
            }
        </div>
                
        <div class="form-group">
            @Html.LabelFor(m => m.SkziKindId, new { @class = "control-label required" })
            <div class="@divCss">
                @Html.DropDownListFor(m => m.SkziKindId, Model.SkziKindAllList, new { @class = @inputCss })
                @Html.ValidationMessageFor(m => m.SkziKindId)
            </div>
        </div>
        
        <div class="form-group">
            @Html.LabelFor(m => m.CopyNumber, new { @class = "control-label required" })
            <div class="@divCss">
                @Html.TextBoxFor(m => m.CopyNumber, new { @class = @inputCss })
                @Html.ValidationMessageFor(m => m.CopyNumber)
            </div>
        </div>
        
        <div class="form-group">
            @Html.LabelFor(m => m.PCId, new { @class = "control-label required" })
            <div class="@divCss">
                @Html.DropDownListFor(m => m.PCId, Model.PCList, new { @class = @inputCss })
                @Html.ValidationMessageFor(m => m.PCId)
            </div>
        </div>
    }    
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-primary submitBtn" id="btnSave">Сохранить</button>
    <button type="button" class="btn btn-default" data-dismiss="modal">Отмена</button>
</div>

<script type="text/javascript" src="@(Url.Content("~/Scripts/AjaxRequest.js"))"></script>    
<script type="text/javascript">
    $(document).ready(function () {
        @if (Model.UserRegisterId == null)
        {
        <text>
            PrepareUserRegisterEdit();
            $("#tbUserFullName").autocomplete("option", "appendTo", "#dlgAddUserSkziDialog");
        </text>
        }
    });

    function SetUserRegister(id, name) {
        $("#UserRegisterId").val(id);
        $("#tbUserFullName").val(name);
        GetPCList();
    }
</script>